
export function createStore(reducer) {
		const currentState = {};
		const currentListeners = [];

		function getState() {
			return currentState;
		}
		function subscribe(listener) {
			currentListeners.push(listener);
		}
		function dispatch(action) {
			reducer(currentState, action);
			currentListeners.forEach(v => v());
			return action;
		}

		// 手动初始化
		dispatch({ type: '@@ghostlpx/mini-redux' });

		return { getState, subscribe, dispatch };
}

function bindActionCreator(creator, dispatch) {
	return (...args) => dispatch(creator(...args));
}

export function bindActionCreators(creators, dispatch) {
	return Object.keys(creators).reduce((ret, item) => {
		ret[item] = bindActionCreator(creators[item], dispatch);
		return ret;
	}, {})
}